import axios from '../../utils/request';

/**
 * 模块名:菜单
 */

// 创建菜单
export interface menuCreatedType {
  name: string;
  menu_code: string;
  node_type: string;
  url: string;
  [propName: string]: any;
}
export function menuCreated(data: menuCreatedType) {
  return axios.request({
    url: '/menus',
    method: 'post',
    data,
  });
}

// 全部菜单
export function list() {
  return axios.request({
    url: '/menus',
    method: 'get',
  });
}

// 子菜单
export function listChild(id: number) {
  return axios.request({
    url: '/menus/' + id,
    method: 'get',
  });
}

// 详情
export function detail(id: string | number | undefined) {
  return axios.request({
    url: '/menus//detail/' + id,
    method: 'get',
  });
}

// 更新菜单
export function menuUpdate(id: number, data: menuCreatedType) {
  return axios.request({
    url: '/menus/' + id,
    method: 'patch',
    data,
  });
}

// 菜单删除
export function menuDel(id: number) {
  return axios.request({
    url: '/menus/' + id,
    method: 'delete',
  });
}

export default { menuDel, menuCreated, listChild, list, menuUpdate, detail };
